// 非递归
const preorder = function(root) {
  const stack = []
  const ans = []
  stack.push(root)
  while(stack.length > 0) {
    let node = stack.pop()
    ans.push(node.val)
    if(node.right) {
      stack.push(node.right)
    }
    if(node.left) {
      stack.push(node.left)
    }
  }
  return ans
}